package com.us.usws.site.console.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

/**
 * base action
 * @author fengyong
 *
 */
public class BaseAction extends ActionSupport {

	private static final long serialVersionUID = -9017654411208920871L;

	public HttpServletRequest getRequest() {
		return ServletActionContext.getRequest();
	}

	public HttpServletResponse getResponse() {
		return ServletActionContext.getResponse();
	}

	public PrintWriter getOut() {
		HttpServletResponse res = getResponse();
		PrintWriter out = null;
		if (res != null) {
			try {
				out = res.getWriter();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return out;
	}

	public HttpSession getSession() {
		HttpServletRequest res = getRequest();

		if (res != null) {
			return res.getSession();
		}
		return null;
	}

	public String getRealPath() {
		return ServletActionContext.getServletContext().getRealPath("/");
	}
}
